<#macro paginate page url orderField="id" orderDirection="desc">
<div class="pagination pagination-large">
    <ul>
        <li class="page_frist"><a href="javascript:void(0);">首页</a></li>
        <li class="page_last"><a href="javascript:void(0);">尾页</a></li>
    </ul>
</div>
<form id="pagination_form" action="${url!}" method="get">
	<input type="hidden" name="pageNumber" value="${(page.pageNumber)!1}">
	<input type="hidden" name="pageSize" value="${(page.pageSize)!1}">
	<input type="hidden" name="totalPage" value="${(page.totalPage)!1}">
	<input type="hidden" name="totalRow" value="${(page.totalRow)!1}">
	<input type="hidden" name="orderField" value="${orderField}">
	<input type="hidden" name="orderDirection" value="${orderDirection}">
	<input type="hidden" name="blogtype" value="${(blog_type.id)!}">
	<input type="hidden" name="tag" value="${(tag.id)!}">
	<input type="hidden" name="keywords" value="${keywords!}">
</form>


<script type="text/javascript">
	//分页组件初始化
	$(function(){
		initPage();
		initPageLink();
	});
	function initPage(){
		var pageNumber = parseInt($('input[name=pageNumber]').val());
		var totalPage = parseInt($('input[name=totalPage]').val());
		//设置禁用页面
		function initActivePage(){
			$('.pagination li').each(function(){
				if($(this).children().text()==pageNumber){
					$(this).addClass("active");
				}
			});
			if(pageNumber==1){
				$('.pagination .page_frist').addClass("disabled");
			}
			if(pageNumber==totalPage){
				$('.pagination .page_last').addClass("disabled");
			}
			if(totalPage==0){
				$('.pagination .page_frist').addClass("disabled");
				$('.pagination .page_last').addClass("disabled");
				var data = "<li class='active'><a href='javascript:void(0);'>没有任何数据</a></li>";
				$('.pagination .page_last').before(data);
			}
		}
		//当前页小于5的情况
		if(pageNumber<=5){
			for(var i=1;i<=10;i++){
				if(i<=totalPage){
					var data = "<li><a href='javascript:void(0);'>"+i+"</a></li>";
					$('.pagination .page_last').before(data);
				}
			}
			 initActivePage();
			return;
		}
		//当前页大于总页数-5的情况
		if(pageNumber>=totalPage-5){
			for(var i=totalPage-9;i<=totalPage;i++){
				if(i<=totalPage){
					var data = "<li><a href='javascript:void(0);'>"+i+"</a></li>";
					$('.pagination .page_last').before(data);
				}
			}
			 initActivePage();
			return;
		}
		//正常情况
		for(var i=pageNumber-5;i<pageNumber;i++){
			if(i>=1){
				var data = "<li><a href='javascript:void(0);'>"+i+"</a></li>";
				$('.pagination .page_last').before(data);
			}
		}
		for(var i=pageNumber;i<(pageNumber+5);i++){
			if(i<=totalPage){
				console.info(pageNumber+5);
				var data = "<li><a href='javascript:void(0);'>"+i+"</a></li>";
				$('.pagination .page_last').before(data);
			}
		}
		initActivePage();
	}
	function initPageLink(){
		var pageNumber = $('input[name=pageNumber]').val();
		$('.pagination li a').click(function(){
			var para = $(this).text();
			var reg = /.*(disabled|active).*/;
			//alert($(this).parent().attr("class"));
			//alert(reg.test($(this).parent().attr("class")));
			if(pageNumber==para||reg.test($(this).parent().attr("class"))){
				return ;
			}
			if(para=="首页"){
				para = 1;
			}
			if(para=="尾页"){
				para = $('input[name=totalPage]').val();
			}
			var url = $('#pagination_form').attr('action')+"/"+para;
			$('#pagination_form').attr('action',url);
			$('#pagination_form').submit();
		});		
	}
	
	
</script>
</#macro>